package com.tbit.uqbike.enums;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: chen
 * @Description:
 * @Date: 创建于 14:38 2023/3/6
 */
public enum WeatherEnum {

    WEATHERENUM_100(100, "晴"),
    WEATHERENUM_101(101, "多云"),
    WEATHERENUM_102(102, "少云"),
    WEATHERENUM_103(103, "晴间多云"),
    WEATHERENUM_104(104, "阴"),
    WEATHERENUM_150(150, "晴"),
    WEATHERENUM_151(151, "多云"),
    WEATHERENUM_152(152, "少云"),
    WEATHERENUM_153(153, "晴间多云"),
    WEATHERENUM_154(154, "晴间多云"),
    WEATHERENUM_300(300, "阵雨"),
    WEATHERENUM_301(301, "强阵雨"),
    WEATHERENUM_302(302, "雷阵雨"),
    WEATHERENUM_303(303, "强雷阵雨"),
    WEATHERENUM_304(304, "雷阵雨伴有冰雹"),
    WEATHERENUM_305(305, "小雨"),
    WEATHERENUM_306(306, "中雨"),
    WEATHERENUM_307(307, "大雨"),
    WEATHERENUM_308(308, "极端降雨"),
    WEATHERENUM_309(309, "毛毛雨/细雨"),
    WEATHERENUM_310(310, "暴雨"),
    WEATHERENUM_311(311, "大暴雨"),
    WEATHERENUM_312(312, "特大暴雨"),
    WEATHERENUM_313(313, "冻雨"),
    WEATHERENUM_314(314, "小到中雨"),
    WEATHERENUM_315(315, "中到大雨"),
    WEATHERENUM_316(316, "大到暴雨"),
    WEATHERENUM_317(317, "暴雨到大暴雨"),
    WEATHERENUM_318(318, "大暴雨到特大暴雨"),
    WEATHERENUM_350(350, "阵雨"),
    WEATHERENUM_351(351, "强阵雨"),
    WEATHERENUM_399(399, "雨"),
    WEATHERENUM_400(400, "小雪"),
    WEATHERENUM_401(401, "中雪"),
    WEATHERENUM_402(402, "大雪"),
    WEATHERENUM_403(403, "暴雪"),
    WEATHERENUM_404(404, "雨夹雪"),
    WEATHERENUM_405(405, "雨雪天气"),
    WEATHERENUM_406(406, "阵雨夹雪"),
    WEATHERENUM_407(407, "阵雪"),
    WEATHERENUM_408(408, "小到中雪"),
    WEATHERENUM_409(409, "中到大雪"),
    WEATHERENUM_410(410, "大到暴雪"),
    WEATHERENUM_456(456, "阵雨夹雪"),
    WEATHERENUM_457(457, "阵雪"),
    WEATHERENUM_499(499, "雪"),
    WEATHERENUM_500(500, "薄雾"),
    WEATHERENUM_501(501, "雾"),
    WEATHERENUM_502(502, "霾"),
    WEATHERENUM_503(503, "扬沙"),
    WEATHERENUM_504(504, "浮尘"),
    WEATHERENUM_507(507, "沙尘暴"),
    WEATHERENUM_508(508, "强沙尘暴"),
    WEATHERENUM_509(509, "浓雾"),
    WEATHERENUM_510(510, "强浓雾"),
    WEATHERENUM_511(511, "中度霾"),
    WEATHERENUM_512(512, "重度霾"),
    WEATHERENUM_513(513, "严重霾"),
    WEATHERENUM_514(514, "大雾"),
    WEATHERENUM_515(515, "特强浓雾"),
    WEATHERENUM_900(900, "热"),
    WEATHERENUM_901(901, "冷"),
    WEATHERENUM_999(999, "未知"),
    ;


    /**
     * 晴
     */
    public static final String sunny = "sunny";
    /**
     * 阴
     */
    public static final String yin = "yin";
    /**
     * 雨
     */
    public static final String rain = "rain";
    /**
     * 雪
     */
    public static final String snow = "snow";
    /**
     * 雾
     */
    public static final String fog = "fog";
    private Integer type;
    private String name;

    WeatherEnum(Integer type, String name) {
        this.type = type;
        this.name = name;
    }

    WeatherEnum() {
    }

    public static String getNameByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (WeatherEnum value : values()) {
            if (value.getType().equals(code)) {
                return value.getName();
            }
        }
        return null;
    }

    public static List<Integer> getNormalType() {
        String normalTypes = "100,101,102,103,104,150,153,154,305,309,500,501,502,504";
        List<String> list = Arrays.asList(normalTypes.split(","));
        List<Integer> l2 = list.stream().map(s -> Integer.valueOf(s)).collect(Collectors.toList());
        return l2;
    }

    /**
     * 天气转换
     *
     * @param type
     * @return
     */
    public static String transFanType(Integer type) {
        if (type <= WEATHERENUM_103.getType() || (type >= WEATHERENUM_150.getType() && type <= WEATHERENUM_154.getType())) {
            return sunny;
        } else if (type.equals(WEATHERENUM_104.getType())) {
            return yin;
        } else if (type >= WEATHERENUM_300.getType() && type <= WEATHERENUM_399.getType()) {
            return rain;
        } else if (type >= WEATHERENUM_400.getType() && type <= WEATHERENUM_499.getType()) {
            return snow;
        } else if (type >= WEATHERENUM_500.getType() && type <= WEATHERENUM_515.getType()) {
            return fog;
        } else {
            return WEATHERENUM_999.getName();
        }
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
